package com.fansl.allround.open.helper.sms;

import com.fansl.allround.common.core.util.SpringContextHolder;
import com.fansl.allround.open.api.entity.sms.SendSmsMessage;
import com.fansl.allround.open.api.entity.sms.SendSmsCodePO;
import lombok.extern.slf4j.Slf4j;

/**
 * @author fansl
 * @Description: 手机短信模板生成策略
 * @date 2019/11/4 16:18
 */
@Slf4j
public class SmsMessageTemplateContext {
    private SmsMessageTemplateExecutor executor;
    private SendSmsCodePO smsCodePO;

    public SmsMessageTemplateContext(SendSmsCodePO smsCodePO){
        this.smsCodePO = smsCodePO;
        builder();
    }

    private void builder(){
        switch (smsCodePO.getSmsCodeType()){
            case LOGIN:
                executor = SpringContextHolder.getBean(LoginMessageTemplateExecutor.class);
            case LOGIN_BIND:
                executor = SpringContextHolder.getBean(BindMessageTemplateExecutor.class);
                break;
        }
    }
    public SendSmsMessage execute() throws Exception{
        if(executor!=null){
            return executor.createMessageTemplate(smsCodePO);
        }
        return null;
    }
}
